import { createVNode, render } from 'vue';
import PreviewImageConstructor from './PreviewImage.vue';

function PreviewImage({ src }) {
  const container = document.createElement('div');
  function onClose() {
    close(container);
  }
  const vm = createVNode(PreviewImageConstructor, { imgSrc: src, onClose });
  render(vm, container);
  document.body.appendChild(container);
}

PreviewImage.open = function (src) {
  PreviewImage({ src });
};

function close(dom) {
  dom.remove();
}

export default PreviewImage;
